package com.qst.controller;

import com.qst.Service.UserService;
import com.qst.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @packageName:com.qst.controller
 * @className:newuserController
 * @Description:
 * @author:zhangyu
 * @date 2021/6/17 22:30
 **/

@Controller
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping(value = "/adduser")
    public String addUser(User user) {
        userService.add(user);
        return "/login";
    }

    @RequestMapping(value = "/getuser")
    public ModelAndView getuser(int id){
        List<User> user = userService.query(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("users", user);
        modelAndView.setViewName("newme");
        return modelAndView;

    }


    @RequestMapping(value = "/updateuser")
    public String update(User user){
        userService.update(user);
        return "redirect:user.do";
    }

}
